import { GET, POST, DELETE, PUT } from '@/utils/request'
import { typeOrderProductItem, typeAddress, typePayment } from '../types/cart'
import { typePaging } from '../types/index'

/**
 * 获取所有订单
 */
export const getOrders = (params:typePaging) => GET(`/order/paging/list`, params)

/**
 * 获取指定用户订单列表
 */
export const getUserOrders = (userId:string, params:typePaging) => GET(`/order/paging/list/${ userId }`, params)

/**
 * 获取单个订单
 */
export const getOrder = (orderId:string) => GET(`/order/${ orderId }`)

interface createOrderPrams {
    productsItems:typeOrderProductItem[],
    shippingAddress:typeAddress,
    paymentMethod: typePayment,
    productsPrice: number,
    shippingPrice: number
}
/**
 * 创建订单
 * @param productsItems 下单的物品
 * @param shippingAddress 收货地址
 * @param paymentMethod 支付方式
 * @param productsPrice 商品总价
 * @param shippingPrice 运费
 */
export const createOrder = (data:createOrderPrams) => POST(`/order`, data)

/**
 * 支付订单
 * @param id 订单id
 */
export const payOrder = (id: string) => POST(`/order/pay/${ id }`)

/**
 * 订单发货
 * @param id 订单id
 */
export const deliverOrder = (id: string) => POST(`/order/deliver/${ id }`)

/**
 * 订单收货
 * @param id 订单id
 */
export const receiveOrder = (id: string) => POST(`/order/receive/${ id }`)
